package com.yd.controller.app;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yd.pojo.Citys;
import com.yd.service.CitysService;
import com.yd.tool.UtsReg;

@Controller
public class CitysControllerApp {
	@Resource
	private CitysService citysService;

	
	@RequestMapping(value = {"/app/citys/list"})
	@ResponseBody
	public String app_citys_list(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();
		
		String page="";
		String size="";
		String pid="0";
		
		if(UtsReg.getIntXl(request.getParameter("page"))){
			page=request.getParameter("page").trim();
		}else{page = "1";}
		if(UtsReg.getIntXl(request.getParameter("size"))){
			size=request.getParameter("size").trim();
		}else{size = "1000";}
		if(UtsReg.getInt(request.getParameter("pid"))){
			pid=request.getParameter("pid").trim();
		}
		
		PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(size));		
		List<Citys> list = null;
		EntityWrapper<Citys> ew=new EntityWrapper<Citys>();
		list=citysService.selectList(ew);
		PageInfo<Citys> pages = new PageInfo<Citys>(list);
		
		jsonObject.put("data", pages);
		jsonObject.put("error", "0");
		jsonObject.put("msg", "成功");
		
		return jsonObject.toString();
	}
	
	
	@RequestMapping(value = {"/app/citys/name/show"})
	@ResponseBody
	public String app_citys_name_show(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();
		String page="";
		String size="";
		String citysname="";
		
		
		if(UtsReg.getStringKB(request.getParameter("citysname"))){
			citysname=request.getParameter("citysname").trim();
		}
		
		if(UtsReg.getIntXl(request.getParameter("page"))){
			page=request.getParameter("page").trim();
		}else{page = "1";}
		if(UtsReg.getIntXl(request.getParameter("size"))){
			size=request.getParameter("size").trim();
		}else{size = "1000";}
		
		PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(size));
		List<Citys> list = null;
		EntityWrapper<Citys> ew=new EntityWrapper<Citys>();
		if(citysname.length()>0){
			ew.like("title", citysname);
		}
		list=citysService.selectList(ew);
		PageInfo<Citys> pages = new PageInfo<Citys>(list);
		
		jsonObject.put("data", pages);
		jsonObject.put("error", "0");
		jsonObject.put("msg", "成功");
		
		return jsonObject.toString();
	}
	
	
	@RequestMapping(value = {"/app/citys/shi/list"})
	@ResponseBody
	public String app_citys_shi_list(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();
		
		String page="";
		String size="";
		String tid="1";
		String hot="";
		
		if(UtsReg.getInt(request.getParameter("tid"))){
			tid=request.getParameter("tid").trim();
		}
		if(UtsReg.getInt(request.getParameter("hot"))){
			hot=request.getParameter("hot").trim();
		}
		if(UtsReg.getStringKB(request.getParameter("page"))){
			page=request.getParameter("page").trim();
		}else{page = "1";}
		if(UtsReg.getStringKB(request.getParameter("size"))){
			size=request.getParameter("size").trim();
		}else{size = "1000";}
		
		PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(size));		
		List<Citys> list = null;
		EntityWrapper<Citys> ew=new EntityWrapper<Citys>();
		list=citysService.selectList(ew.eq("tid", tid).eq("hot", hot));
		PageInfo<Citys> pages = new PageInfo<Citys>(list);
		
		jsonObject.put("data", pages);
		jsonObject.put("error", "0");
		jsonObject.put("msg", "成功");
		
		return jsonObject.toString();
	}
	
}
